package logic

import (
	"context"
	"product_zc/models/mysql"
	"product_zc/productRpc/internal/svc"
	"product_zc/productRpc/productRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ReplyLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewReplyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReplyLogic {
	return &ReplyLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ReplyLogic) Reply(in *productRpc.ReplyRequest) (*productRpc.ReplyResponse, error) {
	// todo: add your logic here and delete this line

	reply := mysql.Reply{
		UserId:    in.UserId,
		ProductId: in.ProductId,
		Content:   in.Content,
	}

	mysql.DB.Create(&reply)

	return &productRpc.ReplyResponse{
		Id: int64(reply.ID),
	}, nil

}
